package com.hongsheng.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hongsheng.mapper.RoleMapper;
import com.hongsheng.pojo.RA;
import com.hongsheng.pojo.Role;
import com.hongsheng.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

/*
@Author：郭振文
@Package：com.hongsheng.service.impl
@File：RoleServiceImpl
@Date：2023/8/10 23:48
*/

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    @Override
    public Boolean insertRole(Role role) {
        int i = roleMapper.insert(role);
        return i>0;
    }

    @Override
    public Boolean deleteRole(Integer id) {
        int i = roleMapper.deleteById(id);
        return i>0;
    }

    @Override
    public Boolean updateRole(Role role) {
        return roleMapper.updateRole(role);
    }

    @Override
    public PageInfo<Role> selectRole(Integer currentPage, Integer pageSize,Role role) {
        PageHelper.startPage(currentPage,pageSize);
        List<Role> roleList = roleMapper.selectRole("%"+role.getRoleName()+"%","%"+role.getDepartment()+"%");
        return new PageInfo<Role>(roleList);
    }

    @Override
    public Role selectRoleById(Integer id) {
        Role role = roleMapper.selectRoleById(id);
        return role;
    }

    @Override
    public Boolean insertRoleAuthority(RA ra) {
        return roleMapper.insertRoleAuthority(ra);
    }

    @Override
    public Boolean deleteRoleAuthority(RA ra) {
        return roleMapper.deleteRoleAuthority(ra);
    }

    @Override
    public List<Role> selectRole1() {
        List<Role> roleList = roleMapper.selectRole1();
        return roleList;
    }

    @Override
    public Boolean selectRA(RA ra) {
        List<RA> raList = roleMapper.selectRA(ra);
        if (raList==null || raList.isEmpty()){
            return true;
        }else {
            return false;
        }

    }


}
